package com.sunjob.loginserver.config;

import cn.dev33.satoken.config.SaSsoConfig;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.sunjob.common.result.Result;
import com.sunjob.loginserver.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-07-24 18:30
 */
@Configuration
public class LoginServerConfig {
    @Autowired
    LoginService loginService;
    @Autowired
    private void configSso(SaSsoConfig sso) {
        // 登录逻辑
        sso.setDoLoginHandle((name, pwd) -> {
            boolean res = loginService.login(name,pwd);
            if(!res){
                return Result.fail("登录失败，用户名或密码错误");
            }
            String tokenVal = StpUtil.getTokenValue();
            return Result.ok(tokenVal,"登录成功");
        });

    }
}
